import { createApp } from 'vue';

import * as HiveIconsVue from 'hive-icons-vue';

// If you want to use ElMessage, import it.
import 'hive-plus/theme-chalk/src/notification.scss'; // 单独引入message样式
import 'hive-plus/theme-chalk/src/message.scss'; // 单独引入message样式
import 'hive-plus/theme-chalk/src/message-box.scss'; // 单独引入notification样式
import 'hive-plus/theme-chalk/src/badge.scss'; // 单独引入badge样式
import '@/styles/index.scss';

import 'virtual:svg-icons-register'; // svg注册器

import App from './App.vue';

import components from '@/components/index';
import { MENU_ICONS } from '@/constants/index';
import directives from '@/directives'; // 自定义全局指令
import router from '@/router';
import { setupStore } from '@/store';

// 性能监控初始化
import { usePerformanceMonitor } from '@/utils/performance';
const performanceMonitor = usePerformanceMonitor();
performanceMonitor.mark('app-setup-start');

// app
const app = createApp(App);
setupStore(app);

for (const [key, component] of Object.entries(HiveIconsVue)) {
  if (MENU_ICONS.includes(key)) {
    app.component(key, component);
  }
}

app
  .use(router)
  .use(components)
  .use(directives)
  .mount('#app');

// 性能监控：应用启动完成
performanceMonitor.mark('app-setup-end');
performanceMonitor.measure('app-setup-time', 'app-setup-start', 'app-setup-end');

// 页面加载完成后打印性能报告
if (typeof window !== 'undefined') {
  window.addEventListener('load', () => {
    // 延迟打印报告，确保所有指标都已收集
    setTimeout(() => {
      performanceMonitor.printPerformanceReport();
    }, 1000);
  });
}
